<template>
	<view class="container-address">
		<noData v-if="lists.length < 1" type="1" ndText="暂无地址"></noData>
		<view class="order-box" v-else v-for="(item,index) in lists" :key="index">
			<view class="order-box-flex" @click="toConfirmOrder(item)">
				<view class="location-content">
					<view class="content-top">
						{{item.name}}<text>{{item.phone}}</text>
					</view>
					<view class="content-bottom">
						{{item.Area.province}}{{item.Area.city}}{{item.Area.region}}{{item.detail}}
					</view>
				</view>
				<image v-show="!conmeAddressTitle" class="right-img"
					src="/static/message/right.png" mode=""></image>
			</view>
			<image class="adress-img" src="/static/message/adress.png" mode=""></image>
			<view class="adress-default">
				<view class="adress-default-left" v-show="item.is_default == 1">
					<image src="/static/message/address-suc.png" mode=""></image>
					<view class="adress-default-left-text">
						默认地址
					</view>
				</view>
				<view class="adress-default-left" v-show="item.is_default == 0" @click="setAddress(item.id)">
					<image src="/static/message/address-default.png" mode=""></image>
					<view class="adress-default-left-text">
						设为默认
					</view>
				</view>
				<view class="adress-default-right"
					@click="navigator('/pages/message/addedAddress/addedAddress?title='+'修改收获地址'+'&addressItem='+ JSON.stringify(item))">编辑</view>
			</view>
		</view>
		<view class="detail-bottom-btn" @click="navigator('/pages/message/addedAddress/addedAddress')">
			新增收货地址
		</view>
	</view>
</template>

<script>
	import noData from '@/components/no-data.vue';
	export default {
		components: {
			noData
		},
		data() {
			return {
				lists: [],
				goosInfo:{},
				conmeAddressTitle:''
			}
		},
		onShow() {
			this.conmeAddressTitle = uni.getStorageSync('conmeAddressTitle')
			this.init();
		},
		methods: {
			toConfirmOrder(item){
				uni.setStorageSync('addressInfo',item)
				uni.setStorageSync('confirmType',1)
				uni.navigateBack({
					delta:1
				})
			},
			// @click="redirecttor('/pages/message/confirmOrder/confirmOrder?addressInfo='+JSON.stringify(item)+'&goosInfo='+JSON.stringify(goosInfo)+'&confirmType='+1)"
			// 跳转
			navigator(url) {
				uni.navigateTo({
					url: url
				})
			},
			// 跳转
			redirecttor(url) {
				uni.redirectTo({
					url: url
				})
			},
			// 列表
			init() {
				this.$http('address.addressLists', {}, '获取中...').then(res => {
					if (res.code == 1) {
						this.lists = res.data
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			},
			// 设置默认地址
			setAddress(id) {
				this.$http('address.setDefault', {
					id: id
				}, '获取中...').then(res => {
					if (res.code == 1) {
						this.lists = []
						uni.showToast({
							icon: 'none',
							title: '设置默认地址成功'
						})
						this.init();
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F6F7F9;
	}

	.container-address {
		padding: 20rpx;

		.order-box {
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			padding: 20rpx;
			margin-bottom: 20rpx;

			.order-box-flex {
				display: flex;
				justify-content: space-between;

				.location-content {
					width: 550rpx;

					.content-top {
						font-weight: 400;
						font-size: 28rpx;
						color: #1A1A1A;

						text {
							margin-left: 20rpx;
						}
					}

					.content-bottom {
						font-weight: 400;
						font-size: 28rpx;
						color: #666666;
						margin-top: 20rpx;
					}
				}

				.right-img {
					width: 12rpx;
					height: 22rpx;
					margin-top: 60rpx;
				}
			}

			.adress-img {
				width: 100%;
				height: 6rpx;
			}

			.adress-default {
				display: flex;
				justify-content: space-between;
				margin-top: 20rpx;

				.adress-default-left {
					display: flex;
					font-weight: 400;
					font-size: 28rpx;
					color: #666666;

					image {
						width: 36rpx;
						height: 36rpx;
						margin-right: 10rpx;
					}
				}

				.adress-default-right {
					font-weight: 400;
					font-size: 28rpx;
					color: #666666;
				}
			}
		}

		.detail-bottom-btn {
			position: fixed;
			z-index: 200;
			bottom: 30rpx;
			width: 686rpx;
			height: 88rpx;
			background: linear-gradient(90deg, #6AAE2B 0%, #1B7E38 100%);
			font-weight: 500;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 88rpx;
			text-align: center;
			left: 50%;
			transform: translate(-50%);
			border-radius: 50rpx;
		}
	}
</style>